//
//  TSSharedNormalViewContainer.m
//  AppCommonJSCollect
//
//  Created by qian on 2023/10/20.
//  Copyright © 2023 dvlproad. All rights reserved.
//

#import "TSSharedNormalViewContainer.h"
#import <Masonry/Masonry.h>

@implementation TSSharedNormalViewContainer

+ (TSSharedNormalViewContainer *)sharedInstance {
    static TSSharedNormalViewContainer *_sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedInstance = [[self alloc] init];
    });
    return _sharedInstance;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        [self setupViews];
    }
    
    return self;
}


- (void)setupViews {
    UIView *container = self;
    container.backgroundColor = [UIColor greenColor];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = [NSString stringWithFormat:@"我是一个视图实例"];
    [container addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(container);
        make.centerY.mas_equalTo(container).mas_offset(-20);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(30);
    }];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setBackgroundColor:[UIColor lightGrayColor]];
    [button setTitle:@"点击我" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(addCount) forControlEvents:UIControlEventTouchUpInside];
    [container addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(container);
        make.centerY.mas_equalTo(container).mas_offset(10);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(30);
    }];
    self.button = button;
}

- (void)addCount {
    self.count++;
    
    NSString *title = [NSString stringWithFormat:@"%ld", self.count];
    [self.button setTitle:title forState:UIControlStateNormal];
}


@end
